#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define LL long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b; i >= a; --i)
int tmpInt;LL tmpLL;string tmpStr;char tmpChar;
vector<int>tmpIntVector;
struct node{
  
};

int main(){
  int t;cin>>t;
  XH(i,0,t){
    LL n,t;cin>>n>>t;
    int meettime = n / 2;
    int meetcnt = (t-1) / meettime;
    int feet = n%2==0?t-1:t-1 + meetcnt;
    int ans = (feet%n)+1;
    cout<<ans<<endl;
  }


  return 0;
}
